package com.artron.mediaartron.data.production;

import com.artron.baselib.utils.UIUtils;
import com.artron.mediaartron.data.entity.FrameData;
import com.artron.mediaartron.data.entity.ImageData;
import com.artron.mediaartron.data.entity.SameSizeFrame;
import com.artron.mediaartron.ui.activity.CustomSelectionActivity;

import java.util.ArrayList;
import java.util.List;

import static android.R.attr.y;
import static android.R.id.list;
import static com.artron.mediaartron.data.production.FrameConstant.FRAME_PRICE;
import static com.artron.mediaartron.data.production.FrameConstant.FRAME_SIZE;
import static com.artron.mediaartron.data.production.FrameConstant.FRAME_SHAPE_TYPE;
import static com.artron.mediaartron.data.production.FrameConstant.FRAME_SKU_NUM;
import static com.artron.mediaartron.data.production.FrameConstant.POSTER_PRICE;
import static com.artron.mediaartron.data.production.FrameConstant.POSTER_SIZE;
import static com.artron.mediaartron.data.production.FrameConstant.POSTER_SKU_NUM;


/**
 * Class description here
 *
 * @author doing
 * @version 1.0.0
 * @since 2017-09-22.
 */

public class CreateFrameData {


    private static List<FrameData> makeVerticalFrame() {
        String[] sizeArr = UIUtils.getStringArray(FRAME_SIZE);
        String[] priceArr = UIUtils.getStringArray(FRAME_PRICE);
        String[] skuNumArr = UIUtils.getStringArray(FRAME_SKU_NUM);

        List<FrameData> list = new ArrayList<>();
        for(int x = 0; x < sizeArr.length; x++) {
            String size = sizeArr[x];
            String[] widthAndHeight = size.split("X");
            int width = Integer.parseInt(widthAndHeight[0]);
            int height = Integer.parseInt(widthAndHeight[1]);
            int price = Integer.parseInt(priceArr[x]);
            String skuNumStr = skuNumArr[x];
            FrameData frame = new FrameData(price, size, height, width, skuNumStr);
            list.add(frame);
        }
        return list;
    }

    public static List<SameSizeFrame> makeSelectionVerticalAllData() {
        List<FrameData> frames = makeVerticalFrame();

        List<SameSizeFrame> list = new ArrayList<>();
        String[] shapeTypeArr = UIUtils.getStringArray(FRAME_SHAPE_TYPE);
        for(int x = 0; x < frames.size(); x++) {
            FrameData frame = frames.get(x);
            List<FrameData> frameList = new ArrayList<>();
            for(int y = 0; y < shapeTypeArr.length; y++) {
                FrameData copy = frame.copy();
                int drawableId = UIUtils.getIdentifier("ic_frame_shape_type" + y, "drawable");
                int drawableNot9Id = UIUtils.getIdentifier("ic_frame_shape_type_not9_" + x, "drawable");
                ImageData image = new ImageData(drawableId, drawableNot9Id, frame.getWidth(), frame.getHeight());
                copy.setShapeType(shapeTypeArr[y]);
                copy.setRightSku(y);
                copy.setImage(image);
                frameList.add(copy);
            }
            SameSizeFrame line = new SameSizeFrame(frameList);
            list.add(line);
        }

        return list;
    }

    private static List<FrameData> makeHorizontalFrame() {
        String[] shapeTypeArr = UIUtils.getStringArray(FRAME_SHAPE_TYPE);

        List<FrameData> list = new ArrayList<>();
        for(int x = 0; x < shapeTypeArr.length; x++) {
            FrameData frame = new FrameData(shapeTypeArr[x]);
            int drawableId = UIUtils.getIdentifier("ic_frame_shape_type" + x, "drawable");
            int drawableNot9Id = UIUtils.getIdentifier("ic_frame_shape_type_not9_" + x, "drawable");
            ImageData image = new ImageData(drawableId, drawableNot9Id);
            frame.setType(CustomSelectionActivity.CUSTOM_MADE);
            frame.setImage(image);
            list.add(frame);
        }
        return list;
    }

    //生成框化数据
    public static List<SameSizeFrame> makeFrameAllData() {
        List<FrameData> frames = makeHorizontalFrame();


        String[] sizeArr = UIUtils.getStringArray(FRAME_SIZE);
        String[] priceArr = UIUtils.getStringArray(FRAME_PRICE);
        String[] skuNumArr = UIUtils.getStringArray(FRAME_SKU_NUM);

        List<SameSizeFrame> list = new ArrayList<>();
        for(int x = 0; x < frames.size(); x++) {
            FrameData frame = frames.get(x);
            List<FrameData> frameList = new ArrayList<>();
            for(int y = 0; y < sizeArr.length; y++) {
                FrameData copy = frame.copy();
                String size = sizeArr[y];
                String[] widthAndHeight = size.split("X");
                int width = Integer.parseInt(widthAndHeight[0]);
                int height = Integer.parseInt(widthAndHeight[1]);
                int price = Integer.parseInt(priceArr[y]);
                String skuNumStr = skuNumArr[y];
                copy.setSize(size);
                copy.setWidth(width);
                copy.setHeight(height);
                copy.setPrice(price);
                copy.setSku(skuNumStr);
                copy.setRightSku(x);
                frameList.add(copy);
            }
            SameSizeFrame line = new SameSizeFrame(frameList);
            list.add(line);
        }

        return list;
    }

    public static List<SameSizeFrame> makePosterAllData() {
        List<FrameData> posters = makeHorizontalPoster();

        String[] sizeArr = UIUtils.getStringArray(POSTER_SIZE);
        String[] priceArr = UIUtils.getStringArray(POSTER_PRICE);
        String[] skuNumArr = UIUtils.getStringArray(POSTER_SKU_NUM);
        String skuNumStr = skuNumArr[0];

        List<SameSizeFrame> list = new ArrayList<>();
        for(int x = 0; x < posters.size(); x++) {
            FrameData frame = posters.get(x);
            List<FrameData> frameList = new ArrayList<>();
            FrameData copy = frame.copy();
            String size = sizeArr[x];
            String[] widthAndHeight = size.split("X");
            int width = Integer.parseInt(widthAndHeight[0]);
            int height = Integer.parseInt(widthAndHeight[1]);
            int price = Integer.parseInt(priceArr[x]);
            copy.setSize(size);
            copy.setWidth(width);
            copy.setHeight(height);
            copy.setPrice(price);
            copy.setSku(skuNumStr);
            copy.setRightSku(x);
            frameList.add(copy);
            SameSizeFrame line = new SameSizeFrame(frameList);
            list.add(line);
        }

        return list;
    }

    private static List<FrameData> makeHorizontalPoster(){
        List<FrameData> list = new ArrayList<>();
        for(int x = 0; x < 5; x++) {
            FrameData frame = new FrameData("外观尺寸");
            frame.setType(CustomSelectionActivity.POSTER);
            int drawableId = UIUtils.getIdentifier("ic_poster_bg", "drawable");
            ImageData image = new ImageData(drawableId, drawableId);
            frame.setImage(image);
            list.add(frame);
        }
        return list;
    }

}
